/*  1:   */ package com.rinsi.core.interceptor;
/*  2:   */ 
/*  3:   */ import com.rinsi.util.AssertUtil;
/*  4:   */ import com.rinsi.util.CaptchaUtil;
/*  5:   */ import com.rinsi.util.MapUtil;
/*  6:   */ import java.io.PrintWriter;
/*  7:   */ import java.util.Map;
/*  8:   */ import javax.servlet.http.HttpServletRequest;
/*  9:   */ import javax.servlet.http.HttpServletResponse;
/* 10:   */ import javax.servlet.http.HttpSession;
/* 11:   */ import org.apache.log4j.Logger;
/* 12:   */ import org.springframework.web.servlet.ModelAndView;
/* 13:   */ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/* 14:   */ 
/* 15:   */ public class ResultInterceptor
/* 16:   */   extends HandlerInterceptorAdapter
/* 17:   */ {
/* 18:26 */   private static Logger logger = Logger.getLogger(ResultInterceptor.class);
/* 19:   */   
/* 20:   */   public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
/* 21:   */     throws Exception
/* 22:   */   {
/* 23:34 */     if (modelAndView != null)
/* 24:   */     {
/* 25:36 */       Map<String, Object> model = modelAndView.getModelMap();
/* 26:   */       
/* 27:38 */       Map<String, Object> params = MapUtil.getMapData(model, "params");
/* 28:   */       
/* 29:40 */       Map<String, Object> config = MapUtil.getMapData(model, "config");
/* 30:43 */       if ((params.containsKey("data_type")) && (params.get("data_type").equals("json")))
/* 31:   */       {
/* 32:45 */         modelAndView.clear();
/* 33:   */         
/* 34:47 */         response.setCharacterEncoding("UTF-8");
/* 35:   */         
/* 36:49 */         response.setContentType("application/json");
/* 37:   */         
/* 38:51 */         PrintWriter out = response.getWriter();
/* 39:   */         
/* 40:53 */         out.print(MapUtil.json(model));
/* 41:   */       }
/* 42:57 */       if ((!params.containsKey("data_type")) || ((params.containsKey("data_type")) && (params.get("data_type").equals("html"))))
/* 43:   */       {
/* 44:59 */         String viewName = MapUtil.getString(config, "module.dir") + "/" + modelAndView.getViewName() + ".jsp";
/* 45:61 */         if (AssertUtil.isStringNotEmpty(MapUtil.getString(model, "viewPage"))) {
/* 46:63 */           viewName = MapUtil.getString(model, "viewPage");
/* 47:   */         }
/* 48:67 */         modelAndView.setViewName(viewName);
/* 49:   */       }
/* 50:71 */       if ((params.containsKey("data_type")) && (params.get("data_type").equals("captcha")))
/* 51:   */       {
/* 52:73 */         modelAndView.clear();
/* 53:   */         
/* 54:75 */         String captcha = CaptchaUtil.getCaptcha(response);
/* 55:   */         
/* 56:77 */         request.getSession().setAttribute("captcha", captcha);
/* 57:   */       }
/* 58:80 */       if (logger.isDebugEnabled()) {
/* 59:82 */         logger.debug("返回结果拦截器信息：" + MapUtil.json(model));
/* 60:   */       }
/* 61:   */     }
/* 62:   */     else
/* 63:   */     {
/* 64:87 */       super.postHandle(request, response, handler, modelAndView);
/* 65:   */     }
/* 66:   */   }
/* 67:   */ }


/* Location:           D:\Users\Desktop\shanxi\项目\sxazmis\WEB-INF\classes\
 * Qualified Name:     com.rinsi.core.interceptor.ResultInterceptor
 * JD-Core Version:    0.7.0.1
 */